<?php
ob_start();

session_start();
include('./inst.conf.php');
include('./functions.php');
//for ($i = 0; $i <= 170000000; $i++) {} //vertraging om het load efect te testen

if(isset($_GET['logoff'])){session_destroy();header("location: ".$_SERVER['PHP_SELF']."");}
if (!isset($_SESSION['LOGIN_USERNAME'] ) || !isset( $_SESSION['LOGIN_PASSWORD'] )){   
	echo "Geen toegang.. log in A.U.B.";
	echo "<script>";
	echo " window.location=\"?logoff\";";
	echo "</script>";
	exit;

}
ob_end_flush();

if (isset($_GET['JSON'])){
echo "[";
echo "	{";
	if(isset($_GET['Del'])){
		if(mysql_query("DELETE FROM `EXTRA_WERK_OPDRACHT` WHERE `EXTRA_WERK_ID` = ".$_GET['Del'])){
			echo '"status"   : "success"';
		}else{
			echo '"status"   : "error",';
			echo '"errorTitle"   : "Mislukt!",';
			echo '"errorText"   : "Er is helaas iets mis gegeaan:<br>'.mysql_error().'"';
		}
	
	}
echo "	}";
echo "]";
exit;
}

//for ($i = 0; $i <= 17000000; $i++) {} //vertraging om het load efect te testen
$COHORT = @$_GET['COHORT'];
$GROEP = @$_GET['GROEP']; 
$LEERLING_ID =@$_GET['LEERLING_ID'];
$RAPPORT_NR = @$_GET['RAPPORT_NR'];
if (isset($_POST['list_cohort'])){
$COHORT = @$_POST['list_cohort'];
$GROEP = @$_POST['list_groep']; 
$LEERLING_ID =@$_POST['list_leerling'];
$RAPPORT_NR =$_POST['list_raport'];
mysql_query("INSERT INTO  `EXTRA_WERK_OPDRACHT` (`EXTRA_WERK_ID` ,`LEERLING_ID` ,`GROEP_ID` ,`RAPPORT_NR` ,`TYPE` ,`OPDRACHT`)VALUES (NULL ,  '".@$_POST['list_leerling']."',  '".@$_POST['list_groep']."',  '$RAPPORT_NR',  '".@$_POST['select']."',  '".secure(@$_POST['text'])."')");
echo "<script>hideLoader();</script>";
}
echo "RAPPORT_NR: $RAPPORT_NR<BR>";
$gegevens = mysql_query("SELECT t1.LEERLING_ID,t1.LEERLINGNUMMER,t1.VOORNAAM,t1.TUSSENVOEGSEL,t1.ACHTERNAAM,t3.TYPE,t3.OPDRACHT, t3.EXTRA_WERK_ID
							 FROM LEERLING AS t1
							 INNER JOIN RAPPORT AS t2 ON ( t1.LEERLING_ID = t2.LEERLING_ID ) 
							 LEFT JOIN EXTRA_WERK_OPDRACHT AS t3 ON ( t1.LEERLING_ID = t3.LEERLING_ID ) AND ( t2.GROEP_ID = t3.GROEP_ID ) AND (t3.RAPPORT_NR='$RAPPORT_NR')
							 WHERE t2.RAPPORT_NR = '0' AND t2.groep_id=".@$GROEP." AND t1.LEERLING_ID=" . @$LEERLING_ID);


?>
<script type="text/javascript">
function extrawerkchnge(){
	$('#invoer2').fadeOut('fast');
	$('#invoer').fadeOut('fast',function() {
		if($('#extrawerk_select').val()==0){
		
		}else if ($('#extrawerk_select').val()==1) {
			$('#txtarea').val('');
		}else if ($('#extrawerk_select').val()==2) {
			$('#txtarea').val('Onderwerp: \nInhoud: \nVerzorging:');
		}else if ($('#extrawerk_select').val()==3) {
			$('#txtarea').val('Onderwerp: \nBeoordeling:');
		}else if ($('#extrawerk_select').val()==4) {
			$('#txtarea').val('Titel: \nEindbeoordeling:');
		}else if ($('#extrawerk_select').val()==5) {
			$('#txtarea').val('');
		}
		$('#invoer').fadeIn('fast');
		$('#invoer2').fadeIn('fast')
	});
}
</script>

<? 
//$database= mysql_fetch_array($gegevens);
//if ($database['TUSSENVOEGSEL'] == ""){$naam = utf8_encode($database['VOORNAAM'] ." ". $database['ACHTERNAAM']);}else{$naam = utf8_encode($database['VOORNAAM'] ." ". $database['TUSSENVOEGSEL'] ." ".  $database['ACHTERNAAM']);}
$body="";
while($data = mysql_fetch_assoc($gegevens)){
	if ($data['TUSSENVOEGSEL'] == ""){$naam = utf8_encode($data['VOORNAAM'] ." ". $data['ACHTERNAAM']);}else{$naam = utf8_encode($data['VOORNAAM'] ." ". $data['TUSSENVOEGSEL'] ." ".  $data['ACHTERNAAM']);}
	
	if($data['TYPE'] <> null){
		if($data['TYPE'] ==1){$type="Extra werk";}elseif ($data['TYPE'] ==2) {$type="Werkstuk";}elseif ($data['TYPE'] ==3) {$type="Spreekbeurt";}elseif ($data['TYPE'] ==4) {$type="Boekbespreking";}elseif ($data['TYPE'] ==5) {$type="Slotopmerking";}
		$body .= "<tr><th>$type</th><td>".nl2br($data['OPDRACHT'])."</td><td><div class=\"but-smal\"><a href=\"javascript:void('0');\" class=\"negative\" name=\"info\" title=\"verwijder\" onclick=\"var obj=this;$.getJSON('./src/extrawerk.invoer.php',{Del: '".$data['EXTRA_WERK_ID']."' , ajax: 'true',JSON: 'true'}, function(json){if(json[0].status == 'success'){\$(obj).closest('tr').hide('fast', function(f){\$(obj).closest('tr').remove()})}else{\$.notify({text: json[0].errorText, title:json[0].errorTitle, icon:'images/dialog-error.png'});}}); \"><img src=\"images/icon-delete_trash.png\" alt=\"X\"/></a></div></td></tr>";
	}else{
		$body .= "<tr><td>niks in database gevonden</td></tr>";
	}
}
echo "<table id=\"table_pages\" name=\"pages\" class=\"tablesorder\">";
echo "<thead>";
echo "<tr><th>".@$naam."</th></tr>";
echo "</thead>";
echo "<tbody>";
echo $body;
echo "</tbody>";
echo "</table>";


echo "<table id=\"table_pages\"   name=\"pages\" class=\"tablesorder\" width=\"100%\">";
echo "<thead>";
echo "<tr><th>Invoeren:</th><th><select id=\"extrawerk_select\" onchange=\"extrawerkchnge()\" name=\"select\"><option value=\"0\"> - Maak uw keuze - </option><option value=\"1\">Extra werk</option><option value=\"2\">Werkstuk</option><option value=\"3\">Spreekbeurt</option><option value=\"4\">Boekbespreking</option><option value=\"5\">Slotopmerking</option></select></th></tr>";
echo "</thead>";
echo "<tbody>";
echo "<tr id=\"invoer\" style=\"display:none;\"><td colspan=2><textarea id=\"txtarea\" style=\"width:99%;height:100px;\" name=\"text\"></textarea></td></tr>";
echo "<tr id=\"invoer2\" style=\"display:none;\"><td colspan=2 align=\"right\">";
echo "	<div class=\"but\">";
echo "	    <a href=\"javascript:void('0');\" class=\"regular\" name=\"save\" id=\"save_butt\" onclick=\"VerzendGegevens();\">";
echo "	        <img src=\"images/icon-save.png\" alt=\"\"/>";
echo "	        Toevoegen";
echo "	    </a>";
echo "	</div>";
echo "</td></tr>";
echo "</tbody>";
echo "</table>";
echo "";


//icon-delete_trash.png
?>


	
